package com.googlecode.afdbaccess.web.common.exception;

import com.googlecode.afdbaccess.web.common.util.HtmlEscaper;

public class GuiLayerExtJsFormValuesException extends GuiLayerJsonFormattedException {
    public GuiLayerExtJsFormValuesException(String message, String longMessage, String fieldId, String fieldErrorMessage, Throwable cause) {
        super(message, longMessage, createJsonErrorString(fieldId, fieldErrorMessage), cause);
        setHttpReturnCode(200);
    }
    
    public GuiLayerExtJsFormValuesException(String message, String longMessage, String fieldId, String fieldErrorMessage) {
        super(message, longMessage, createJsonErrorString(fieldId, fieldErrorMessage));
        setHttpReturnCode(200);
    }
    
    //
    
    private static String createJsonErrorString(String fieldId, String fieldErrorMessage) {
        return "errors: {'" + HtmlEscaper.escapeStringForJavaScript(fieldId) + "':'" + HtmlEscaper.escapeStringForJavaScript(fieldErrorMessage) + "'}";
    }
}
